package com.jinzhi.jzweb.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jinzhi.api.exception.IFastApiException;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.type.ApiEnumError;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.TrackDrawDO;
import com.jinzhi.jzweb.domain.TrackDrawRegularDO;
import com.jinzhi.jzweb.pojo.TrackDrawRegularSignComVO;
import com.jinzhi.jzweb.pojo.TrackDrawRegularVO;
import com.jinzhi.jzweb.service.TrackDrawRegularService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 *
 * <pre>
 * 赛道抽签表（存储抽签信息）
 * </pre>
 * <small> 2023-10-16 16:36:18 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/trackDrawRegularSignCom")
public class TrackDrawRegularSignComController extends BaseController {

	@Autowired
	private TrackDrawRegularService trackDrawRegularService;


	/**
	 *
	 * 抽选手部分
	 *
	 */
	@GetMapping()
	@RequiresPermissions("jzweb:trackDrawRegularSignCom:trackDrawRegularSignCom")
	String TrackDrawSignCom(){
		return "jzweb/trackDrawRegularSignCom/trackDrawRegularSignCom";
	}



	/**
	 * 查询选手
	 * @param trackDrawRegularDTO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/listSignCom")
	@RequiresPermissions("jzweb:trackDrawRegularSignCom:trackDrawRegularSignCom")
	public Result<Set<String>> listSignCom(TrackDrawRegularDO trackDrawRegularDTO){


		return trackDrawRegularService.listSignCom(trackDrawRegularDTO);
	}

	/**
	 * 对选手进行抽签
	 * @param trackDrawRegularDTO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/listTrackDrawRegularSignCom")
	@RequiresPermissions("jzweb:trackDrawRegularSignCom:trackDrawRegularSignCom")
	public Result<List<TrackDrawRegularDO>> listTrackDrawRegularSignCom(TrackDrawRegularDO trackDrawRegularDTO){

		return trackDrawRegularService.trackRegularListSignCom(trackDrawRegularDTO);
	}


	/**
	 * 导出选手抽签结果信息
	 *
	 * @param response
	 */
	@Log("导出选手抽签结果信息")
	@RequestMapping("/downloadImportTemplateSignCom")
	@RequiresPermissions("jzweb:trackDrawRegularSignCom:import")
	@ResponseBody
	public void downloadImportTemplateSignCom(HttpServletRequest request, HttpServletResponse response, TrackDrawDO trackDrawDTO) {
		Wrapper<TrackDrawRegularDO> wrapper = new EntityWrapper<>();
		wrapper.orderBy(true,"sort");
		List<TrackDrawRegularDO> trackDrawDOS = trackDrawRegularService.selectList(wrapper);
		if (trackDrawDOS != null && trackDrawDOS.size() > 0) {
			List<TrackDrawRegularSignComVO> drawRegularVOList = new ArrayList<>();
			for (TrackDrawRegularDO trackDrawDO : trackDrawDOS) {
				TrackDrawRegularSignComVO trackDrawRegularSignComVO = new TrackDrawRegularSignComVO();
				BeanUtils.copyProperties(trackDrawDO,trackDrawRegularSignComVO);
				drawRegularVOList.add(trackDrawRegularSignComVO);
			}
			//导出操作
			EasyPoiUtil.exportExcel(drawRegularVOList, "选手抽签信息", "选手抽签信息", TrackDrawRegularSignComVO.class,  "选手抽签信息", response);
		} else {
			throw new IFastApiException(ApiEnumError.NOTBATCHSTU.getCodeStr());
		}
	}


}
